package com.ymttest.database.mongo;

import java.util.ArrayList;
import java.util.Map;

import org.json.JSONArray;

import com.mongodb.BasicDBObject;
import com.mongodb.WriteResult;
import com.sun.org.apache.bcel.internal.generic.NEW;
import com.ymt.core.tool.Logger;
import com.ymt.database.MongoDBDriver;
import com.ymttest.database.mongo.jproduct.ProductsWapper;
import com.ymttest.datadriver.SqlSearch;
import com.ymttest.utils.MapUtil;

/************************************************************************************
 * @File name :LiveProductInfoWapper.java
 * @Author : xujiewei
 * @Date : 2016年6月28日
 * @Copyright : 洋码头
 * 商品合库 新库
 ************************************************************************************/
public class ProductDetailModelWapper implements SqlSearch{
	MongoDBDriver mdd = YmtMongoDriverFactroy.getInstance_YmtProductDBdriverNew("ProductDetailModel");

	public ProductDetailModelWapper()  {
	}
		

	public Map<String,Object> getProductId(String productId) throws Exception {
		ArrayList<Map> list = mdd.selectPartLimitToMap("{\"ProductId\":\"" + productId + "\"}",1);
	    
	    return list.size()>0?list.get(0):null;
	}
	    
	
	public boolean update(Map<String, Object> searchMap,Map<String, Object> updateMap) throws Exception{
		return  mdd.update(searchMap, updateMap).isUpdateOfExisting();
	}
	public boolean updateAll(Map<String, Object> searchMap,Map<String, Object> updateMap) throws Exception{
		BasicDBObject queryObject = new BasicDBObject(searchMap);
		BasicDBObject updateObject = new BasicDBObject("$set", updateMap);
		WriteResult wr = mdd.getCollection().update(queryObject, updateObject,false,true);
		return  wr.isUpdateOfExisting();
	}
	
	public int getCountByProductId(String productId) throws Exception{
		return mdd.selectPartLimitToMap("{\"ProductId\":\"" + productId + "\"}",50).size();
	}
	
	
	public static void main(String[] args) throws Exception {
		
		System.out.println(new ProductDetailModelWapper().updateAll(MapUtil.hashMap("SellerId", 3383, "IsNew", true),MapUtil.hashMap("IsNew", false)));
		
	}


	@Override
	public Map selectBy(Map<String, Object> searchMap) {
		
		return null;
	}
}
